package com.techgene.kanban.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class AdminAuthenticationInterceptor implements HandlerInterceptor 
{
	/**
	 * This method traps the admin pages for the authentication purpose
	 * 
	 */
	 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	 {
		 
		 HttpSession session = request.getSession(false);
	        if(session == null || !("admin".equals(session.getAttribute("user_role"))))
	        {
	        	response.sendRedirect(request.getContextPath()+"/login?statussMsg=Login Again");
	        	return false;
	        }
		 return true;
	 }
	 
	 
	 
	 public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception 
	 {}
	 
	 
	 
	 public void afterCompletion(HttpServletRequest request,HttpServletResponse response, Object handler, Exception ex)throws Exception 
	 {}
	
}
